home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / boot_up / bmpshow2 / bmpshow.c < prev    next >
C/C++ Source or Header  |  1995-04-27  |  21KB  |  693 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <aes.h>
  5. #include <vdi.h>
  6. #include <tos.h>
  7. #include <ext.h>
  8.  
  9. #define min(a, b)             ((a) < (b) ? (a) : (b))
  10. #define max(a, b)             ((a) > (b) ? (a) : (b))
  11. #define TRUE 1
  12. #define FALSE 0
  13.  
  14. typedef struct tagBITMAPFILEHEADER
  15. {
  16.         unsigned int  bfType;                   /* "BM" or 0x4D42 */
  17.         unsigned long bfSize;                   /* Size of file in bytes */
  18.         unsigned int  bfReserved1;              /* Set to 0 */
  19.         unsigned int  bfReserved2;              /* Set to 0 */
  20.         unsigned long bfOffBits;                /* Offset in file where */
  21.                                                 /* the bits begin */
  22. } BITMAPFILEHEADER;
  23.  
  24. typedef struct tagBITMAPINFOHEADER
  25. {
  26.         unsigned long biSize;                   /* Size of the structure */
  27.         unsigned long biWidth;                  /* Width in pixels */
  28.         unsigned long biHeight;                 /* Height in pixels  */
  29.         unsigned int  biPlanes;                 /* # of color Planes: Set to 1 */
  30.         unsigned int  biBitCount;               /* Color bits per pixel */
  31.         unsigned long biCompression;            /* Compression Scheme */
  32.         unsigned long biSizeImage;              /* Number of bitmap bytes */
  33.         unsigned long biXPelsPerMeter;          /* Horizontal Resolution */
  34.         unsigned long biYPelsPerMeter;          /* Vertical Resolution */
  35.         unsigned long biClrUsed;                /* Number of colors used */
  36.         unsigned long biClrImportant;           /* Important colors */
  37.  
  38. } BITMAPINFOHEADER;
  39.  
  40. BITMAPFILEHEADER BMPHeader;
  41. BITMAPINFOHEADER BMPInfo;
  42.  
  43. FILE *fn;
  44. int     Msgbuff[8];                 
  45. int     W_handle, Wx, Wy, Ww, Wh;             
  46. int     W_fulled;                                            
  47. int     pxarray[128];               
  48. int     Done = FALSE;              
  49. int     work_in[12];
  50. int     work_out[57];
  51. int     extend_out[57];
  52. int     handle, phys_handle;
  53. int     gl_hchar,gl_wchar,gl_hbox,gl_wbox;
  54. int     gl_apid;
  55. int     xdesk, ydesk, wdesk, hdesk;
  56. int     hidden;
  57. int     xyarray[256];
  58. unsigned int  color_correction[1024];
  59. unsigned char colortable[1024][4];
  60. unsigned char color[2048];
  61. int     pallatte[1024];
  62. int     rgbcolors[1024][3];
  63. int     hw_index;
  64. int     vdi_index;
  65. int i;
  66. int xy[4];
  67. char path[128];
  68. char fname[16];
  69. char pathfname[144];
  70. char c_temp[1024];
  71. long file_length;
  72.  
  73. void close_vwork( void );
  74. int open_vwork( void );
  75. int fixint(int data);
  76. long fixlong(long data);
  77. int setcolors(FILE *fn);
  78. void put8bits(void);
  79. void put4bits(void);
  80. void put2bits(void);
  81. void put1bits(void);
  82. void fake_calc(void);
  83. void show_mouse(void);
  84. void hide_mouse(void);
  85. extern int (*byte2raw)(char *col, char *screen);
  86. extern int (*p_pixel)(int x, int y, int color);
  87. extern int pinit(int max_x, int max_y, void *video_buffer, int planes);
  88. extern void pexit(void);
  89. extern set16_pixel8(int x, int y, char *color);
  90.  
  91. main(int argc, char *argv[])
  92. {
  93.    struct ffblk fblock;
  94.    char *cptr;
  95.    int flag = 0;
  96.    
  97.    FILE *Fn;
  98.    while(Bconstat(2)) Bconin(2);
  99.    
  100.    if(argc < 2) 
  101.    {
  102.       puts("No filename given");
  103.       Bconin(2);
  104.       return;
  105.    }
  106.  
  107.    if ( open_vwork( ) == TRUE )
  108.    {
  109.       pinit(work_out[0]+1, work_out[1]+1, (void *)Logbase(), extend_out[4]);
  110.       for(i = 0; i < work_out[13]; i++) {
  111.          vq_color(handle, i, 1, (int *)&rgbcolors[i]);
  112.          xy[0] = 0;
  113.          xy[1] = 0;
  114.          vsm_color(handle, i); 
  115.          v_pmarker(handle, 1, xy);
  116.          v_get_pixel(handle, 0, 0, &hw_index, &vdi_index);
  117.          color_correction[hw_index] = vdi_index;
  118.       }
  119.       show_mouse();
  120.    }
  121.    else
  122.    {
  123.       fprintf(stderr, "Unable to start Program!" );
  124.       exit ( -1 );
  125.    }
  126.    
  127.    sprintf(c_temp, "%s", argv[1]); /* copy the commandline string. */
  128.  
  129.    /* Now strip the path from the string. */
  130.    i = strlen(c_temp);
  131.    cptr = c_temp + i;
  132.    
  133.    while(i > 0) {
  134.       if(*cptr == ':') {
  135.          sprintf(fname, "%s", cptr+1);
  136.          *(cptr+1) = 0;
  137.          sprintf(path, "%s\\", c_temp);
  138.          break;
  139.       }
  140.       if(*cptr == '\\') {
  141.          sprintf(fname, "%s", cptr+1);
  142.          *(cptr+1) = 0;
  143.          sprintf(path, "%s", c_temp);         
  144.          break;
  145.       }
  146.       
  147.       i--;
  148.       cptr--;
  149.    }      
  150.    
  151.    if(i <= 0) {
  152.       path[0] = 0;
  153.       sprintf(fname, "%s", c_temp);
  154.    }
  155.    
  156.    if(strlen(fname) <= 0) {
  157.       sprintf(fname,"*.BMP");
  158.    }
  159.    
  160.    sprintf(pathfname, "%s%s", path, fname);
  161.    
  162.    flag = findfirst(pathfname, &fblock, 0);
  163.    
  164.    while(flag == 0) {
  165.    
  166.       sprintf(pathfname, "%s%s", path, fblock.ff_name);
  167.       sprintf(fname,"%s",fblock.ff_name);
  168.       file_length = fblock.ff_fsize;
  169.       
  170.       Bconout(2, 27);
  171.       Bconout(2, 'E');
  172.       puts(fname);
  173.       
  174.       Fn = fopen(pathfname,"rb");               /* Open up BMP image file  */   
  175.         
  176.       if(Fn == (FILE *)0) {
  177.          printf("File %s not found\n", argv[1]);
  178.          Bconin(2);
  179.          close_vwork( );
  180.          exit(0);
  181.       }                                                   
  182.                                                 /* Read in BMP header */
  183.       fread(&BMPHeader, sizeof(BMPHeader), 1, Fn);
  184.       fread(&BMPInfo, sizeof(BMPInfo), 1, Fn);
  185.       fclose(Fn);
  186.       
  187.       if(BMPHeader.bfType != 0x424d) {
  188.          printf("File %s Not a Windows .BMP file\n", argv[1]);
  189.          Bconin(2);
  190.          close_vwork( );
  191.          exit(0);
  192.       }
  193.    
  194.       /* Convert INTEL to MOTOROLA format. */
  195.  
  196.       BMPHeader.bfSize        = fixlong(BMPHeader.bfSize);        /* Size of file in bytes */
  197.       BMPHeader.bfOffBits     = fixlong(BMPHeader.bfOffBits);     /* Offset in file where */
  198.       BMPInfo.biSize          = fixlong(BMPInfo.biSize);          /* Size of the structure */
  199.       BMPInfo.biWidth         = fixlong(BMPInfo.biWidth);         /* Width in pixels */
  200.       BMPInfo.biHeight        = fixlong(BMPInfo.biHeight);        /* Height in pixels  */
  201.       BMPInfo.biPlanes        = fixint(BMPInfo.biPlanes);         /* # of color Planes: Set to 1 */
  202.       BMPInfo.biBitCount      = fixint(BMPInfo.biBitCount);       /* Color bits per pixel */
  203.       BMPInfo.biCompression   = fixlong(BMPInfo.biCompression);   /* Compression Scheme */
  204.       BMPInfo.biSizeImage     = fixlong(BMPInfo.biSizeImage);     /* Number of bitmap bytes */
  205.       BMPInfo.biXPelsPerMeter = fixlong(BMPInfo.biXPelsPerMeter); /* Horizontal Resolution */
  206.       BMPInfo.biYPelsPerMeter = fixlong(BMPInfo.biYPelsPerMeter); /* Vertical Resolution */
  207.       BMPInfo.biClrUsed       = fixlong(BMPInfo.biClrUsed);       /* Number of colors used */
  208.       BMPInfo.biClrImportant  = fixlong(BMPInfo.biClrImportant);  /* Important colors */
  209.  
  210.       switch(BMPInfo.biBitCount) {
  211.          case 1: put1bits(); break;
  212.          case 2: put2bits(); break;
  213.          case 4: put4bits(); break;
  214.          case 8: put8bits(); break;                          
  215.          default: printf("\rOnly 1/2/4 and 8 bit color currently supported\n");
  216.        }
  217.       flag = findnext(&fblock);
  218.    }
  219.    
  220.    close_vwork( );
  221.    exit ( 0 );
  222.    return 0;
  223. }
  224.  
  225. /***************************************************************/
  226. /* */
  227. /***************************************************************/
  228. void put8bits(void) 
  229. {
  230.    FILE *Fn;
  231.    register int x, maxx, y, pmaxx;
  232.    int i;
  233.    register char *screen;
  234.    register char *Color;
  235.    int kpress;
  236.    extern long *_ytable;
  237.    
  238.    while(Bconstat(2)) Bconin(2);
  239.  
  240.    y = BMPInfo.biHeight;
  241.    
  242.    if(BMPInfo.biSizeImage == 0L)
  243.       maxx = (int) ((unsigned long) (file_length - BMPHeader.bfOffBits) / (unsigned long)y);
  244.    else
  245.       maxx = (int) ((unsigned long) BMPInfo.biSizeImage / (unsigned long)y);
  246.  
  247.    for(i = 0; i < 2048; color[i++] = 0);
  248.    
  249.    Fn = fopen(pathfname, "rb");                  /* Open BMP file */
  250.    setvbuf(Fn, (char *)0, _IOFBF, (size_t) file_length);
  251.    
  252.    if(extend_out[4] > 1)
  253.       setcolors(Fn);
  254.  
  255.    fseek(Fn,BMPHeader.bfOffBits,SEEK_SET); /* BMP file */
  256.  
  257.    pmaxx = maxx;
  258.    if(y > work_out[1] - 1) y = work_out[1] - 1;
  259.    if(maxx > work_out[0]) pmaxx = work_out[0];
  260.  
  261.    Color = color;
  262.    
  263.    do {
  264.       fread(&color, maxx, 1, Fn);
  265.       screen = (char *) *(_ytable + y + 1);   
  266.       for (x = 0; x < pmaxx;) {
  267.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  268.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  269.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  270.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  271.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  272.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  273.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  274.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  275.       }
  276.       if(Bconstat(2)) break;
  277.    } while (y-- > 0);
  278.    
  279.    fclose(Fn);
  280.    
  281.    kpress = (int)Bconin(2) & 0xff;
  282.    Bconout(2, 27);
  283.    Bconout(2, 'E');
  284.    
  285.    if(kpress == 27) {
  286.       fake_calc();
  287.    }else
  288.       return;
  289. }
  290.  
  291. /***************************************************************/
  292. /* */
  293. /***************************************************************/
  294. void put4bits(void) 
  295. {
  296.    FILE *Fn;
  297.    register int x, maxx, y, pmaxx;
  298.    register char *screen;
  299.    register char *Color;
  300.    int kpress;
  301.    int i, j;
  302.    extern long *_ytable;
  303.    
  304.    while(Bconstat(2)) Bconin(2);
  305.  
  306.    y = BMPInfo.biHeight;
  307.    
  308.    if(BMPInfo.biSizeImage == 0L)
  309.       maxx = (int) ((unsigned long) (file_length - BMPHeader.bfOffBits) / (unsigned long)y);
  310.    else
  311.       maxx = (int) ((unsigned long) BMPInfo.biSizeImage / (unsigned long)y);
  312.  
  313.    maxx <<= 1; /* adjust for true width. */
  314.    
  315.    for(i = 0; i < 2048; color[i++] = 0);
  316.  
  317.    Fn = fopen(pathfname, "rb");                  /* Open BMP file */
  318.    setvbuf(Fn, (char *)0, _IOFBF, (size_t) file_length);
  319.    
  320.    if(extend_out[4] > 1)
  321.       setcolors(Fn);
  322.  
  323.    fseek(Fn,BMPHeader.bfOffBits,SEEK_SET); /* BMP file */
  324.  
  325.    pmaxx = maxx;
  326.    if(y > work_out[1] - 1) y = work_out[1] - 1;
  327.    if(maxx > work_out[0]) pmaxx = work_out[0];
  328.  
  329.    Color = c_temp;
  330.    
  331.    do {
  332.       fread(&color, maxx >> 1, 1, Fn);
  333.       
  334.       j = 0;
  335.       for(i = 0; i < (maxx >> 1); i++) {
  336.          c_temp[j++] = (color[i] >> 4) & 0xf;
  337.          c_temp[j++] =  color[i] & 0xf;
  338.       }
  339.       
  340.       screen = (char *) *(_ytable + y + 1);   
  341.       for (x = 0; x < pmaxx;) {
  342.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  343.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  344.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  345.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  346.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  347.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  348.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  349.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  350.       }
  351.       if(Bconstat(2)) break;
  352.    } while (y-- > 0);
  353.    
  354.    fclose(Fn);
  355.    
  356.    kpress = (int)Bconin(2) & 0xff;
  357.    Bconout(2, 27);
  358.    Bconout(2, 'E');
  359.    
  360.    if(kpress == 27) {
  361.       fake_calc();
  362.    }else
  363.       return;
  364. }
  365. /***************************************************************/
  366. /* */
  367. /***************************************************************/
  368. void put2bits(void) 
  369. {
  370.    FILE *Fn;
  371.    register int x, maxx, y, pmaxx;
  372.    register char *screen;
  373.    register char *Color;
  374.    int kpress;
  375.    int i, j;
  376.    extern long *_ytable;
  377.    
  378.    while(Bconstat(2)) Bconin(2);
  379.  
  380.    y = BMPInfo.biHeight;
  381.    
  382.    if(BMPInfo.biSizeImage == 0L)
  383.       maxx = (int) ((unsigned long) (file_length - BMPHeader.bfOffBits) / (unsigned long)y);
  384.    else
  385.       maxx = (int) ((unsigned long) BMPInfo.biSizeImage / (unsigned long)y);
  386.  
  387.    maxx <<= 2; /* adjust for true width. */
  388.  
  389.    for(i = 0; i < 2048; color[i++] = 0);
  390.  
  391.    Fn = fopen(pathfname, "rb");                  /* Open BMP file */
  392.    setvbuf(Fn, (char *)0, _IOFBF, (size_t) file_length);
  393.    
  394.    if(extend_out[4] > 1)
  395.       setcolors(Fn);
  396.  
  397.    fseek(Fn,BMPHeader.bfOffBits,SEEK_SET); /* BMP file */
  398.  
  399.    pmaxx = maxx;
  400.    if(y > work_out[1] - 1) y = work_out[1] - 1;
  401.    if(maxx > work_out[0]) pmaxx = work_out[0];
  402.  
  403.    Color = c_temp;
  404.    do {
  405.       fread(&color, maxx >> 2, 1, Fn);
  406.       
  407.       j = 0;
  408.       for(i = 0; i < (maxx >> 2); i++) {
  409.          c_temp[j++] = (color[i] >> 6) & 0x3;
  410.          c_temp[j++] = (color[i] >> 4) & 0x3;
  411.          c_temp[j++] = (color[i] >> 2) & 0x3;
  412.          c_temp[j++] =  color[i] & 0x3;
  413.       }
  414.       
  415.       screen = (char *) *(_ytable + y + 1);   
  416.       for (x = 0; x < pmaxx;) {
  417.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  418.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  419.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  420.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  421.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  422.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  423.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  424.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  425.       }
  426.       if(Bconstat(2)) break;
  427.    } while (y-- > 0);
  428.    
  429.    fclose(Fn);
  430.    
  431.    kpress = (int)Bconin(2) & 0xff;
  432.    Bconout(2, 27);
  433.    Bconout(2, 'E');
  434.    
  435.    if(kpress == 27) {
  436.       fake_calc();
  437.    }else
  438.       return;
  439. }
  440.  
  441. /***************************************************************/
  442. /* */
  443. /***************************************************************/
  444. void put1bits(void) 
  445. {
  446.    FILE *Fn;
  447.    register int x, maxx, y, pmaxx;
  448.    register char *screen;
  449.    register char *Color;
  450.    int kpress;
  451.    int i, j;
  452.    extern long *_ytable;
  453.    
  454.    while(Bconstat(2)) Bconin(2);
  455.  
  456.    y = BMPInfo.biHeight;
  457.    
  458.    if(BMPInfo.biSizeImage == 0L)
  459.       maxx = (int) ((unsigned long) (file_length - BMPHeader.bfOffBits) / (unsigned long)y);
  460.    else
  461.       maxx = (int) ((unsigned long) BMPInfo.biSizeImage / (unsigned long)y);
  462.  
  463.    maxx <<= 3; /* adjust for true width. */
  464.  
  465.    for(i = 0; i < 2048; color[i++] = 0);
  466.  
  467.    Fn = fopen(pathfname, "rb");                  /* Open BMP file */
  468.    setvbuf(Fn, (char *)0, _IOFBF, (size_t) file_length);
  469.       
  470.    if(extend_out[4] > 1)
  471.       setcolors(Fn);
  472.  
  473.    fseek(Fn,BMPHeader.bfOffBits,SEEK_SET); /* BMP file */
  474.    pmaxx = maxx;
  475.    if(y > work_out[1] - 1) y = work_out[1] - 1;
  476.    if(maxx > work_out[0]) pmaxx = work_out[0];
  477.  
  478.    Color = c_temp;
  479.    
  480.    do {
  481.       fread(&color, maxx >> 3, 1, Fn);
  482.       
  483.       j = 0;
  484.       for(i = 0; i < (maxx >> 3); i++) {
  485.          c_temp[j++] = (color[i] >> 7) & 0x1;
  486.          c_temp[j++] = (color[i] >> 6) & 0x1;
  487.          c_temp[j++] = (color[i] >> 5) & 0x1;
  488.          c_temp[j++] = (color[i] >> 4) & 0x1;
  489.          c_temp[j++] = (color[i] >> 3) & 0x1;
  490.          c_temp[j++] = (color[i] >> 2) & 0x1;
  491.          c_temp[j++] = (color[i] >> 1) & 0x1;
  492.          c_temp[j++] =  color[i] & 0x1;
  493.       }
  494.       
  495.       screen = (char *) *(_ytable + y + 1);   
  496.       for (x = 0; x < pmaxx;) {
  497.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  498.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  499.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  500.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  501.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  502.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  503.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  504.          screen += (long)(*byte2raw)(Color+x, screen); x += 16;
  505.       }
  506.       if(Bconstat(2)) break;
  507.    } while (y-- > 0);
  508.    
  509.    fclose(Fn);
  510.    
  511.    kpress = (int)Bconin(2) & 0xff;
  512.    Bconout(2, 27);
  513.    Bconout(2, 'E');
  514.    
  515.    if(kpress == 27) {
  516.       fake_calc();
  517.    }else
  518.       return;
  519. }
  520.  
  521. /***************************************************************/
  522. /* */
  523. /***************************************************************/
  524. int setcolors(FILE *fn)
  525. {
  526.    int offset;
  527.    int count;
  528.    int rgb[3];
  529.  
  530.    offset = sizeof(BMPInfo) + sizeof(BMPHeader);
  531.    count = BMPHeader.bfOffBits - offset;
  532.    fseek(fn,offset,SEEK_SET); /* BMP file */
  533.    fread(colortable,count,1,fn);
  534.    
  535.    /* Convert to VDI levels. 1000/255 = 3.921568627 */
  536.    for(count = 0; count < work_out[13]; count++) {
  537.       rgb[2] = (int)((float)(colortable[count][0])) * 3.921568627;
  538.       rgb[1] = (int)((float)(colortable[count][1])) * 3.921568627;
  539.       rgb[0] = (int)((float)(colortable[count][2])) * 3.921568627;
  540.  
  541.       /* When setting the palette our putpixel routine is based */
  542.       /* on the hardware color not VDI which is not always to   */
  543.       /* same. So make the correction here.                     */
  544.       vs_color(handle, color_correction[count], rgb);
  545.    }
  546. }
  547.  
  548. /***************************************************************/
  549. /* */
  550. /***************************************************************/
  551.  
  552. int open_vwork( void )
  553. {
  554.    register int i;
  555.  
  556.    if (( gl_apid = appl_init() ) != -1 )
  557.    {
  558.       for ( i = 1; i < 10; work_in[i++] = 1 );
  559.       work_in[10] = 2;
  560.       phys_handle = graf_handle( &gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox );
  561.       work_in[0]  = handle = phys_handle;
  562.  
  563.       v_opnvwk( work_in, &handle, work_out );
  564.       vq_extnd(handle, 1, extend_out);
  565.       
  566.       return ( TRUE );
  567.    }
  568.    else
  569.       return ( FALSE );
  570. }
  571. /***************************************************************/
  572. /* */
  573. /***************************************************************/
  574. void hide_mouse(void)
  575. {
  576.    if(! hidden)
  577.    {
  578.       graf_mouse(M_OFF,0x0L);
  579.       hidden=TRUE;
  580.    }
  581. }
  582. /***************************************************************/
  583. /* */
  584. /***************************************************************/
  585.  
  586. void show_mouse(void)
  587. {
  588.    if(hidden)
  589.    {
  590.       graf_mouse(M_ON,0x0L);
  591.       hidden=FALSE;
  592.    }
  593. }
  594.  
  595. /*************************************************************************/
  596. /* Close Work Station.                                                   */
  597. /*************************************************************************/
  598.  
  599. void close_vwork( void )
  600. {
  601.    int i;
  602.    
  603.    for(i = 0; i < work_out[13]; i++)
  604.       vs_color(handle, i, (int *)&rgbcolors[i]);
  605.  
  606.    v_clsvwk( handle );
  607.    pexit();
  608.    appl_exit( );
  609. }
  610. /***************************************************************/
  611. /* convert intel to motorola format                            */
  612. /***************************************************************/
  613. long fixlong(long data)
  614. {
  615.    char byte[4];
  616.    char *bptr = (char *) &data;
  617.  
  618.    byte[0] = *(bptr+3);
  619.    byte[1] = *(bptr+2);
  620.    byte[2] = *(bptr+1);
  621.    byte[3] = *(bptr);
  622.  
  623.    data = *((long *)byte);
  624.    return(data);
  625. }
  626. /***************************************************************/
  627. /* convert intel to motorola format                            */
  628. /***************************************************************/
  629. int fixint(int data)
  630. {
  631.    char byte[2];
  632.    char *bptr = (char *)&data;
  633.  
  634.    byte[0] = *(bptr+1);
  635.    byte[1] = *(bptr);
  636.  
  637.    data = *((int *)byte);
  638.    return(data);
  639. }
  640.  
  641. /****************************************************************/
  642. /* Calc long axis of visual counter part.                       */
  643. /****************************************************************/
  644. void fake_calc(void) 
  645. {
  646. #ifdef DONT_WANT_WIFE_TO_SEE
  647.    int i;
  648.    int j;
  649.    int number_of_loops;
  650.    int spit_number;
  651.    
  652.    Bconout(2, 27);
  653.    Bconout(2, 'E');
  654.       
  655.    for(i = 0; i < work_out[13]; i++)
  656.       vs_color(handle, i, (int *)&rgbcolors[i]);
  657.       
  658.    while(Bconstat(2)) Bconin(2);
  659.    
  660.    j = 0;
  661.    i = 0;
  662.    spit_number = (int) (Random() & 0x3f) + 1;
  663.    while(1) {
  664.       if((i++ % spit_number) == 0) {
  665.          printf("\r Return Value = %ld ", Random());
  666.          j = 0;
  667.          spit_number = (int) (Random() & 0x3f) + 1;
  668.       }
  669.          
  670.       if((j++ % 78) == 0) 
  671.          printf("\n");
  672.       else
  673.          printf("*");
  674.          
  675.       delay((int)(Random() & 0x1ff));
  676.       
  677.       if(Bconstat(2)) {
  678.          number_of_loops = (int) Bconin(2) & 0xff;
  679.          switch(number_of_loops) {
  680.             case 'Q':
  681.             case 'q': close_vwork();
  682.                       exit(0);
  683.             case 'R':
  684.             case 'r':
  685.                       return;
  686.          }             
  687.       }
  688.    }
  689. #else
  690.    close_vwork();
  691.    exit(0);
  692. #endif
  693. }